package org.takeback.chat.service.support.ord;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.WebSocketSession;
import org.takeback.chat.entity.Message;
import org.takeback.chat.store.room.Room;
import org.takeback.chat.store.user.User;
import org.takeback.chat.utils.MessageUtils;

@Component("showRoomMembersCmd")
public class ShowRoomMembersCmd implements Command {

	@Override
	public void exec(Map map, Message message, WebSocketSession websocketsession, Room room, User user) {
		List<Map<String, Object>> members = Lists.newArrayList();
		Collection<User> users = room.getUsers().values();
		for (User u : users) {
			Map<String, Object> d = Maps.newHashMap();
			d.put("id", u.getId());
			d.put("nickName", u.getNickName());
			d.put("headImg", u.getHeadImg());
			d.put("handsUp", u.getHandsUp());
			members.add(d);
		}
		MessageUtils.sendCMD(websocketsession, "showRoomMembers", members);
	}
}
